<?
//获得符合条件的数据某个项的数值总和:
//$condition:
//table:表格名称
//item:要统计那个项
//例子:sum_total("finance","applydate like '".date("Y-m-d")."%' and status = '生效' ")
function sum_total($table,$item,$condition)
{



  if($condition)
  {
    $condition="where $condition";
  }
  else
  {
    $condition="";
  }


 $sqlstr="select sum($item) as total_value from $table $condition";


  $values = mysql_result(mysql_query($sqlstr), 0);

  //当无数值返回的时候，就需要设置为0
  if(!$values){$values=0;}

return $values;

}


?>

